﻿using System;
using System.Collections.Generic;
using System.Text;


public enum TextureFormat
{
    R8,
    //A8, alpha 格式贴图不总是支持，干脆统一换r8 
    RGBA32,
}
public interface IResource : IDisposable
{
    uint ID
    {
        get;
    }

}
public interface ITexture : IResource
{

    TextureFormat format
    {
        get;
    }
    int width
    {
        get;
    }
    int height
    {
        get;
    }
    bool isStatic
    {
        get;
    }
}
/// <summary>
/// RenderTexture+Camera 的概念
/// </summary>
public interface IRenderTarget : ITexture
{
    //RenderTarget 的观察点
    bool FlipY { get; }
    ColorF ClearColor
    {
        get;
        set;
    }
    //Vector2 LookAt
    //{
    //    get;
    //    set;
    //}
    ////
    //float Scale
    //{
    //    get;
    //    set;
    //}
    void Begin();
    void End();
}
public interface IRenderer
{
    IRenderTarget Target
    {
        get;
    }
    string Name
    {
        get;
    }
    Vector2 LookAt
    {
        get;
        set;
    }
    //
    float Scale
    {
        get;
        set;
    }
}
public interface IBatcher : IRenderer
{
    void DrawRect(ITexture tex, Effect effect, RectangleF rect, Rectangle uv, Color32 color);
    //void DrawRect(ITexture tex, RectangleF rect, Rectangle uv, Color32 color);
    //void DrawRect(ITexture tex, Vector2 pos, Rectangle uv, Color32 color);

    void DrawRectFree(ITexture tex, Effect effect, DrawPoint point0, DrawPoint point1, DrawPoint point2, DrawPoint point3);

    void DrawTris(ITexture tex, Effect effect, DrawPoint[] tris, int tricount);
    void DrawLines(ITexture tex, Effect effect, DrawPoint[] lines, int linecount);
    void DrawPoints(ITexture tex, Effect effect, DrawPoint[] points, int pointcount);

    void BeginDraw();
    void EndDraw();
}
//特殊绘制效果
public class Effect
{
    public string effect;
    public string[] strparams;
    public float[] numparams;
}

public struct DrawPoint
{
    public Vector3 pos;
    public Vector2 uv;
    public Color32 color;
}
public interface IGraphic
{
    ITexture TextureWhite
    {
        get;
    }
    ITexture CreateStaticTexture(int w, int h, TextureFormat format, byte[] data);

    IRenderTarget CreateRenderTarget(int w, int h, TextureFormat format);

    ITexture CreateDynamicTexture(int w, int h, TextureFormat format);

    void UploadTexture(ITexture tex, int x, int y, int w, int h, byte[] data);
    void ApplyTexture(ITexture texture, bool TurnToStatic = false);

    //截图，异步，为了迁就有些系统无法同步截图
    void ReadPixel(IRenderTarget target, Action<TextureFormat, int, int, byte[]> onReadBack);

    //Begin End 机制交给实现层管理，每一个RenderTarget会调用一次OnRender，放在不同的阶段处理
    //void BeginRender(IRenderTarget target, Color clearColor);
    //void EndRender();

    IBatcher CreateRenderer_Batcher(IRenderTarget target);
    //IBatcher Batcher
    //{
    //    get;
    //}
    //void DrawRect(ITexture tex, Effect effect, RectangleF rect, Rectangle uv, Color color);
    //void DrawRect(ITexture tex, RectangleF rect, Rectangle uv, Color color);
    //void DrawRect(ITexture tex, Vector2 pos, Rectangle uv, Color color);

    //void DrawRectFree(ITexture tex, Effect effect, DrawPoint point0, DrawPoint point1, DrawPoint point2, DrawPoint point3);

    //void DrawTris(ITexture tex, Effect effect, DrawPoint[] tris, int tricount);
    //void DrawLines(ITexture tex, Effect effect, DrawPoint[] lines, int linecount);
    //void DrawPoints(ITexture tex, Effect effect, DrawPoint[] points, int pointcount);
    /// <summary>
    /// 只有一个显示区域
    /// </summary>
    IRenderTarget MainScreen
    {
        get;
    }

    event Action OnPreRender;

    event Action OnRender;

    //好像没啥必要
    //event Action<IRenderTarget> OnRenderTarget;

    //void PreRender_DrawTarget(IRenderTarget target);
}
